<template>
  <div style="height: 100%; width: 100%; position: relative">
    <div :class="!is_showselother ? 'pagetop' : 'pagetopother'">
      <div style="height: 100%">
        <table border="0" style="width: 100%; font-size: 12px; width: 100%; white-space: nowrap" class="table1style">
          <col style="width: 5%" />
          <col style="width: 11%" />
          <col style="width: 1%" />
          <col style="width: 11%" />
          <col style="width: 5%" />
          <col style="width: 11%" />
          <col style="width: 5%" />
          <col style="width: 9%" />
          <col style="width: 5%" />
          <col style="width: 9%" />
          <col style="width: 5%" />
          <col style="width: 9%" />
          <col style="width: 5%" />
          <col style="width: 9%" />
          <tr>
            <td align="right">
              <el-dropdown @command="handleCommand" style="font-size: 12px">
                <u class="el-dropdown-link">
                  {{ datename }}
                </u>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item command="标本日期">
                    <font font-size="12px">标本日期</font>
                  </el-dropdown-item>
                  <el-dropdown-item command="报告日期">
                    <font font-size="12px">报告日期</font>
                  </el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown>
            </td>
            <td>
              <el-date-picker v-model="searchobj.strdate" :clearable="false" type="date" placeholder="选择日期"
                value-format="yyyy-MM-dd" style="width: 100%"> </el-date-picker>
            </td>
            <td style="text-align: center">至</td>
            <td>
              <el-date-picker v-model="searchobj.enddate" type="date" :clearable="false" placeholder="选择日期"
                value-format="yyyy-MM-dd" style="width: 100%"> </el-date-picker>
            </td>
            <td align="right">报告单元</td>
            <td>
              <rm-ddl-rptunit prgno="LIS973" :clearable="false" defaultflag="" v-model="searchobj.rptunitid"
                key="1"></rm-ddl-rptunit>
            </td>
            <td align="right">申请科室</td>
            <td>
              <el-select v-model="searchobj.reqdept"
                @dblclick.native="popMultipleChk(searchobj.reqdept, 'reqdept', deptOption, '申请科室选择')" filterable
                clearable>
                <el-option v-for="(item, index) in deptOption" :key="index" :value="item.data" :label="item.display">
                </el-option>
              </el-select>
            </td>
            <td align="right">标本类型</td>
            <td>
              <el-select v-model="searchobj.txtspecimen"
                @dblclick.native="popMultipleChk(txtspecimen, 'txtspecimen', specimenOption, '标本类型选择')" filterable
                clearable>
                <el-option v-for="(item, index) in specimenOption" :key="index" :value="item.data" :label="item.display">
                </el-option>
              </el-select>
            </td>
            <td align="right">导出条件</td>
            <td>
              <el-popover style="width: 200px" trigger="click" placement="bottom" v-model="exportConditionVisible">
                <div style="height: 300px; width: 450px">
                  <div style="width: 200px; float: left; margin: 10px">
                    <el-divider content-position="left">导出要求</el-divider>
                    <table>
                      <tr>
                        <td>
                          <el-checkbox true-label="1" false-label="0"
                            v-model="exportobj.PatnoShowPatid">病人号显示病人ID</el-checkbox>
                        </td>
                      </tr>
                      <tr>
                        <td>
                          <el-checkbox true-label="1" false-label="0"
                            v-model="exportobj.micIsEmptyNouseResultFlag">Mic为空不使用结果标志代替</el-checkbox>
                        </td>
                        <td>
                          <el-checkbox true-label="1" false-label="0"
                            v-model="exportobj.OnlyMicNotEmpty">仅导出Mic不为空的数据</el-checkbox>
                        </td>
                      </tr>
                      <tr>
                        <td>
                          <el-checkbox true-label="1" false-label="0"
                            v-model="exportobj.radIsEmptyNouseResultFlag">Rad为空不使用结果标志代替</el-checkbox>
                        </td>
                        <td>
                          <el-checkbox true-label="1" false-label="0"
                            v-model="exportobj.OnlyRadNotEmpty">仅导出Rad不为空的数据</el-checkbox>
                        </td>
                      </tr>
                    </table>
                  </div>
                  <div style="width: 100%; float: left; margin: 10px">
                    <el-divider content-position="left">导出时剔除药敏结果中的以下符号</el-divider>
                    <table>
                      <tr>
                        <td>
                          <el-checkbox v-model="exportobj.chkdayu" true-label="1" false-label="0">&gt;</el-checkbox>
                          <el-checkbox v-model="exportobj.chkxiaoyu" true-label="1" false-label="0">&lt;</el-checkbox>
                          <el-checkbox v-model="exportobj.chkdayudengyu" true-label="1"
                            false-label="0">&gt;=</el-checkbox>
                          <el-checkbox v-model="exportobj.chkxiaoyudengyu" true-label="1"
                            false-label="0">&lt;=</el-checkbox>
                          <el-checkbox v-model="exportobj.chksynr" true-label="1" false-label="0">SYN-R导出
                            &gt;=1000</el-checkbox>
                          <el-checkbox v-model="exportobj.chksyns" true-label="1" false-label="0">SYN-S导出 &lt;=500 </el-checkbox>
                        </td>
                      </tr>
                    </table>
                  </div>
                  <div style="width: 100%; float: left; margin: 10px">
                    <el-button @click.native="ExportConditionSure">确定</el-button>
                    <el-button @click.native="ExportConditionClear">清除</el-button>
                    <el-button @click.native="exportConditionVisible = false">取消</el-button>
                  </div>
                </div>
                <el-input slot="reference" style="cursor: pointer" readonly placeholder="点击展开导出条件" clearable></el-input>
              </el-popover>
            </td>
            <td colspan="2" align="center">
              <el-link :underline="false" @click="btn_showselother">{{ is_showselother ? "收起其它条件" : "展开其它条件" }}<i
                  :class="is_showselother ? 'el-icon-caret-top' : 'el-icon-caret-bottom'"></i> </el-link>
            </td>
          </tr>
          <tr v-show="is_showselother">
            <td align="right">标本号</td>
            <td colspan="3">
              <el-input v-model="searchobj.txtbarcode" @keyup.enter.native="FunQuery" style="width: 100%"></el-input>
            </td>
            <td align="right">检验仪器</td>
            <td>
              <rm-ddl-instrument v-model="searchobj.txtlabinstrument" :clearable="true"></rm-ddl-instrument>
            </td>
            <td align="right">病历号</td>
            <td>
              <el-input v-model="searchobj.patno" clearable></el-input>
            </td>
            <td align="right">病人姓名</td>
            <td>
              <el-input v-model="searchobj.txtpatname" @keyup.enter.native="FunQuery" style="width: 100%"></el-input>
            </td>
            <td align="right">病人来源</td>
            <td>
              <el-select v-model="searchobj.pattype"
                @dblclick.native="popMultipleChk(searchobj.pattype, 'pattype', pattypeOption, '病人来源')" filterable
                clearable style="width: 200px">
                <el-option v-for="(item, index) in pattypeOption" :key="index" :value="item.data" :label="item.display">
                </el-option>
              </el-select>
              <!-- <rm-ddl-common datatype="seccode" kindno="PT" dataname="病人来源" v-model="searchobj.pattype" width="100%"></rm-ddl-common> -->
            </td>
            <td align="right">科室取值</td>
            <td>
              <el-select v-model="searchobj.deptmode">
                <el-option v-for="(item, index) in deptmodeOption" :key="index" :label="item.label"
                  :value="item.value"></el-option>
              </el-select>
            </td>
          </tr>
          <tr v-show="is_showselother">
            <td align="right">送检医院</td>
            <td colspan="3">
              <table style="border-spacing: 0px">
                <tr>
                  <td>
                    <rm-ddl-common datatype="hospital" dataname="医院" v-model="searchobj.hospcode"
                      width="100%"></rm-ddl-common>
                  </td>
                  <td>
                    &nbsp; <el-checkbox true-label="1" false-label="0" v-model="searchobj.containHospcodeIsEmpty"><span
                        style="font-size: 12px">包含送检院区为空的</span></el-checkbox>
                  </td>
                </tr>
              </table>
            </td>
            <td align="right">所属病区</td>
            <td>
              <el-select v-model="searchobj.txtwardno"
                @dblclick.native="popMultipleChk(searchobj.txtwardno, 'txtwardno', wardOption, '病区选择')" filterable
                clearable style="width: 100%">
                <el-option v-for="(item, index) in wardOption" :key="index" :value="item.data" :label="item.display">
                </el-option>
              </el-select>
            </td>
            <td align="right">细菌组合</td>
            <td colspan="3">
              <table style="border-spacing: 0px">
                <tr>
                  <td>
                    <el-select style="width: 150px" v-model="searchobj.germcomb"
                      @dblclick.native="popMultipleChk(searchobj.germcomb, 'germcomb', germcombOption, '细菌组')" filterable
                      clearable>
                      <el-option v-for="(item, index) in germcombOption" :key="index" :value="item.data"
                        :label="item.display"> </el-option>
                    </el-select>
                  </td>
                  <td>&nbsp;</td>
                  <td>
                    <el-checkbox true-label="1" false-label="0" v-model="searchobj.rejectGermComb"><span
                        style="font-size: 12px">剔除菌组</span></el-checkbox>
                  </td>
                </tr>
              </table>
            </td>
            <td align="right">耐药机制</td>
            <td style="width: 450px">
              <rm-ddl-common datatype="resdict" dataname="耐药机制" v-model="searchobj.txtrescode"></rm-ddl-common>
            </td>
            <td colspan="2" align="right">
              <el-checkbox true-label="1" false-label="0" v-model="exportobj.delCopySample">剔除复制标本</el-checkbox>
            </td>
          </tr>
          <tr v-show="is_showselother">
            <td align="right">真菌标志</td>
            <td>
              <el-select v-model="searchobj.germgramflag">
                <el-option value="0" label="全部"></el-option>
                <el-option value="1" label="真菌"></el-option>
                <el-option value="2" label="细菌"></el-option>
              </el-select>
            </td>
            <td align="right">实验室代码</td>
            <td>
              <el-input v-model="searchobj.laboratory" style="width: 100%"></el-input>
            </td>
            <td colspan="3" align="center">
              <el-radio-group v-model="searchobj.onlyposresult">
                <el-radio :label="0">全部</el-radio>
                <el-radio :label="1">阳性菌</el-radio>
                <el-radio :label="2">带药敏</el-radio>
                <el-radio :label="3">剔除涂片</el-radio>
              </el-radio-group>
            </td>
            <td></td>
            <td colspan="6" align="center">
              <el-radio-group v-model="searchobj.deletedup">
                <el-radio :label="1">去除同一个病人的相同结果</el-radio>
                <el-radio :label="2">去除同一个病人同标本类型的相同结果</el-radio>
                <el-radio :label="0">不去除</el-radio>
              </el-radio-group>
            </td>
          </tr>
          <tr>
            <td colspan="14" align="right">
              <el-button @click.native="BtnQuery" type="primary" icon="el-icon-search">查询</el-button>
              <el-button @click.native="BtnClear" icon="el-icon-close">清除</el-button>
              <!-- <el-button @click.native="BtnExport" icon="el-icon-download">导出</el-button> -->
              <!-- <el-button slot="reference" icon="el-icon-download" @click="BtnDbf">DBF导出</el-button> -->
              <el-button @click.native="BtnExportDrugNet" icon="el-icon-check">导出到耐药网</el-button>
            </td>
          </tr>
        </table>
      </div>
    </div>
    <div :class="!is_showselother ? 'pagecenter' : 'pagecenterother'">
      <rm-layout-right splitcolor="white" movingcolor="#0000ff" :splitwidth="5" :fixsize="400">
        <template v-slot:fix>
          <div v-if="execexport" style="overflow: hidden">
            <el-button @click.native="stopexport" class="el-button--310" icon="el-icon-video-pause">停止导出</el-button>
            <div style="height: 100%; overflow: auto">
              <div ref="exportmsgdivref" id="exportmsgdiv" style="height: auto; width: 100%; overflow: hidden"
                v-html="logListstr"></div>
            </div>
          </div>
          <vxe-table v-else :data.sync="rightTableData" :select-config="{ reserve: true }"
            :sort-config="{ trigger: 'cell' }" border height="auto" highlight-current-row class="mytable-style"
            highlight-hover-column highlight-hover-row how-header-overflow ref="rightxTable" resizable show-overflow
            size="mini" stripe show-header-overflow :optimization="{ animat: false }" header-align="center"
            :loading="rightloading">
            <vxe-table-column type="index" title="NO." width="40" align="center"></vxe-table-column>
            <vxe-table-column field="medname" sortable title="抗生素" width="120"></vxe-table-column>
            <vxe-table-column field="rad" sortable title="Rad" width="60" align="center"></vxe-table-column>
            <vxe-table-column field="mic" sortable title="Mic" width="60" align="center"></vxe-table-column>
            <vxe-table-column field="medresult" sortable title="药敏结果" width="60" align="center"></vxe-table-column>
            <vxe-table-column field="result_flag" sortable title="标志" width="40" align="center"></vxe-table-column>
            <vxe-table-column field="result6" sortable title="参考范围" width="70"></vxe-table-column>
            <vxe-table-column field="expertresult" sortable title="专家值" width="60" align="center"></vxe-table-column>
            <vxe-table-column field="medgroup" sortable title="分组" width="60" align="center"></vxe-table-column>
            <vxe-table-column field="whonetcolidx" sortable title="导出列" width="60" align="center"></vxe-table-column>
          </vxe-table>
        </template>
        <div style="height: 100%; width: 100%">
          <vxe-table :data.sync="leftTableData" :select-config="{ reserve: true, checkAll: true }"
            :sort-config="{ trigger: 'cell' }" border height="auto" highlight-current-row class="mytable-style"
            highlight-hover-column highlight-hover-row how-header-overflow ref="leftxTable" resizable show-overflow
            size="mini" stripe show-header-overflow :optimization="{ animat: false }" header-align="center"
            :loading="leftloading" @current-change="currentChangeEvent"
            :edit-config="{ trigger: 'click', mode: 'cell', activeMethod: CellActive, showStatus: true, showIcon: false }">
            <vxe-table-column type="selection" width="40" align="center"> </vxe-table-column>
            <vxe-table-column field="rechkflag" sortable title="审核" width="40" align="center">
              <template v-slot="{ row }">
                <span style="font-size: 16px; color: blue">{{ row.rechkflag == "9" ? "审" : "" }}</span>
              </template>
            </vxe-table-column>
            <vxe-table-column field="rptunitid" sortable title="报告单元" width="120"
              :formatter="formatFun"></vxe-table-column>
            <vxe-table-column field="sampledate" sortable title="标本日期" width="80" align="center"
              :formatter="['toDateString', 'yyyy-MM-dd']"></vxe-table-column>
            <vxe-table-column field="sampleno" sortable title="标本编号" width="80" align="center"></vxe-table-column>
            <vxe-table-column field="pat_name" sortable title="姓名" width="50" align="center"></vxe-table-column>
            <vxe-table-column field="pat_no" sortable title="病人号" width="70"></vxe-table-column>
            <vxe-table-column field="pat_sex" sortable title="性别" width="40" align="center"
              :edit-render="{ name: 'select', options: $opt.patSex }"></vxe-table-column>
            <vxe-table-column field="pat_agestr" sortable title="年龄" width="50" align="center"></vxe-table-column>
            <vxe-table-column field="specimen_code" sortable title="标本类型" width="80" align="center"
              :formatter="formatFun"></vxe-table-column>
            <vxe-table-column field="rpt_itemcode" sortable title="项目代码" width="80"></vxe-table-column>
            <vxe-table-column field="rpt_itemname" sortable title="培养结果/检验项目" width="150"></vxe-table-column>
            <vxe-table-column field="result_str" sortable title="检验结果" width="80" align="center"></vxe-table-column>
            <vxe-table-column field="result1" sortable title="菌落计数" width="70" align="center"></vxe-table-column>
            <vxe-table-column field="result4" sortable title="耐药机制" width="70"></vxe-table-column>
            <vxe-table-column field="instrid" sortable title="检验仪器" width="80" align="center"
              :formatter="formatFun"></vxe-table-column>
            <vxe-table-column field="result2" sortable title="特殊结果2" width="80" align="center"></vxe-table-column>
            <vxe-table-column field="req_deptno" sortable title="申请科室" width="100"
              :formatter="formatFun"></vxe-table-column>
            <vxe-table-column field="req_bedno" sortable title="床号" width="60" align="center"></vxe-table-column>
            <vxe-table-column field="barcode" sortable title="条码号" width="90" align="center"></vxe-table-column>
            <vxe-table-column field="rechk_dt" sortable title="审核时间" width="120" align="center"></vxe-table-column>
            <vxe-table-column field="rechk_user" sortable title="审核医生" width="70" align="center"
              :formatter="formatFun"></vxe-table-column>
            <vxe-table-column field="pat_typecode" sortable title="病人类别" width="60" align="center"
              :formatter="formatFun"></vxe-table-column>
            <vxe-table-column field="req_wardno" sortable title="病人病区" width="90"
              :formatter="formatFun"></vxe-table-column>
            <vxe-table-column field="result_txt" sortable title="专家评语" width="90" align="center"></vxe-table-column>

            <template v-slot:fix>
              <div style="font-size: 17px; text-align: center; background-color: #fff; color: blue">
                <span>共{{ rowcount }}行</span>
              </div>
            </template>
          </vxe-table>
        </div>
      </rm-layout-right>
      <el-dialog title="上传DBF模板" :visible.sync="bDbfExportVisible" width="30%" height="300px">
        <el-upload :action="url" accept=".dbf" :before-upload="beforeUploadFile" :show-file-list="showFile"
          :file-list="fileList" :data="updata" :http-request="uploadOpt" class="upload-demo" multiple>
          <div slot="tip" class="el-upload__tip">上传dbf文件，获取导出格式。</div>
          <el-button size="small" type="primary">点击上传</el-button>
        </el-upload>
      </el-dialog>
      <el-dialog title="提示" :visible.sync="bMsgExportVisible" width="30%" height="300px">
        <span>是否使用现有模板进行DBF导出？</span>
        <span slot="footer" class="dialog-footer">
          <el-button type="primary" @click="BtnDBFExport()">确 定</el-button>
          <el-button @click="
            bMsgExportVisible = false;
          bDbfExportVisible = true;
          ">更新模板</el-button>
          <el-button @click="bMsgExportVisible = false">取 消</el-button>
        </span>
      </el-dialog>
      <el-dialog title="dbf导出结果" :visible.sync="bShowlogVisible" width="750px" height="500px" :append-to-body="true"
        :close-on-click-modal="false">
        <div style="width: 100%; height: 500px"></div>
      </el-dialog>

      <!--多选弹窗--->
      <el-dialog width="900px" v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false"
        :title="multichktitle" :visible.sync="dialogMultipleVisible" :destroy-on-close="true">
        <rm-SqlMultiple :leftOption="option1" :rightOption="option2" :name="fieldname"
          @change="closedialog"></rm-SqlMultiple>
      </el-dialog>
    </div>
  </div>
</template>

<script type="text/javascript">
import XEUtils from "xe-utils";
import axios from "axios";
// import RmSelecttable from "@/components/rmcompents/rm_selecttable.vue";
export default {
  name: "LIS973",
  components: {
    // RmSelecttable
  },
  data() {
    return {
      searchobj: {
        strdate: this.$pub.InitDate(),
        enddate: this.$pub.InitDate(),
        onlyposresult: 2,
        deletedup: 1,
        deptmode: "1",
        reqdept: "",
        txtwardno: "",
        pattype: "",
        germgramflag: "0",
        laboratory: "LIS",
      },
      sumcnt: 0,
      exportobj: {
        chksynr: "1",
        chksyns: "1",
      },
      leftTableData: [],
      rightTableData: [],
      url: "",
      showFile: false,
      leftloading: false,
      rightloading: false,
      is_showselother: false,
      bShowlogVisible: false,
      bDbfExportVisible: false,
      bMsgExportVisible: false,
      exportConditionVisible: false,
      topkey: 0,
      datename: "标本日期",
      datetype: "1",
      deptmodeOption: [
        { label: "", value: "" },
        { label: "科室", value: "1" },
        { label: "病区", value: "2" },
        { label: "科室_病区", value: "3" },
      ],
      fileList: [],
      rptArr: [],
      codeArr: [],
      logList: [],
      pattypeOption: [],
      deptOption: [],
      wardOption: [],
      hospOption: [],
      germcombOption: [],
      rptunitOption: [],
      specimenOption: [],
      doctorOption: [],
      userOption: [],
      instrOption: [],
      whonetextensionname: "",
      updata: { action: "LIB110" },
      exportdata: [],
      logListstr: "",
      searchtxt: "",
      onekeywhonet: true,
      tab_name: "tab_dept",
      execexport: false,
      stopexec: false,

      dialogMultipleVisible: false,
      multichktitle: "",
      fieldname: "",
      option1: [],
      option2: [],
    };
  },
  created() {
    this.initOption();
  },
  computed: {
    rowcount() {
      return this.leftTableData.length;
    },
  },
  mounted() {
    // this.init();
    this.url = this.$tool.baseUrl.replace(/api/, "z") + "fileupload";
    this.getDeptmode();
  },
  methods: {
    getDeptmode() {
      let deptmode = localStorage.getItem("lis973deptmode");
      if (deptmode) this.searchobj.deptmode = deptmode;
      let exportobj = JSON.parse(localStorage.getItem("lis973exportobj"));
      if (exportobj) this.exportobj = exportobj;
      let laboratory = localStorage.getItem("lis973laboratory");
      if (laboratory) this.searchobj.laboratory = laboratory;
    },
    popMultipleChk(e, fieldname, option, title) {
      let temp = XEUtils.clone(option, true);
      this.option1 = [];
      this.option2 = [];
      if (e != "") {
        let k = e.split(",");
        k.forEach((item) => {
          let ndata = temp.find((m) => m.data == item);
          if (ndata != undefined && ndata != null) {
            this.option2.push(ndata);
          }
        });
        temp.forEach((item) => {
          if (k.indexOf(item.data + "") < 0) {
            this.option1.push(item);
          }
        });
      } else {
        this.option1 = temp;
      }
      this.fieldname = fieldname;
      this.multichktitle = title;
      this.dialogMultipleVisible = true;
    },
    closedialog(value, name) {
      if (value != "close") {
        this.searchobj[name] = value;
      }
      this.dialogMultipleVisible = false;
    },

    async initOption() {
      try {
        const res = await this.$tool.request({
          url: "LIS/LIS9/LIS973",
          method: "post",
          data: {
            action: "getOption",
          },
        });

        this.pattypeOption = res.pattypeOption;
        this.deptOption = res.deptOption;
        this.hospOption = res.hospOption;
        this.doctorOption = res.doctorOption;
        this.rptunitOption = res.rptunitOption;
        // this.rptunitGroupOption = res.rptunitGroupOption;
        this.wardOption = res.wardOption;
        this.germcombOption = res.germcombOption;
        this.specimenOption = res.specimenOption;
        this.userOption = res.userOption;
        this.instrOption = res.instrOption;
        this.whonetextensionname = res.whonetextensionname;
      } catch (e) {
        this.$message.warning(e);
      }
    },
    BtnQuery() {
      this.execexport = false;
      this.leftloading = true;
      this.$tool
        .request({
          url: "LIS/LIS9/LIS973",
          method: "post",
          data: {
            action: "query",
            daytype: this.datetype,
            ...this.searchobj,
          },
        })
        .then((response) => {
          if (response.errcode == "1") {
            this.leftTableData = response.Data;
            if (response.Data.length > 0) {
              this.$refs.leftxTable.setCurrentRow(this.leftTableData[0]);
              this.queryRight(this.leftTableData[0]);
              this.is_showselother = false;
            } else {
              this.leftTableData = [];
              this.rightTableData = [];
            }
          } else {
            this.$alert(response.errmsg, "提示");
            this.leftTableData = [];
            this.rightTableData = [];
          }
          this.leftloading = false;
        })
        .catch((e) => {
          this.$alert(e, "出错");
          this.leftloading = false;
        });
      localStorage.setItem("lis973deptmode", this.searchobj.deptmode); // 记录当前科室取值 本地
      localStorage.setItem("lis973laboratory", this.searchobj.laboratory); // 记录当前实验室代码 本地
      localStorage.setItem("lis973exportobj", JSON.stringify(this.exportobj));
    },
    currentChangeEvent({ row }) {
      this.queryRight(row);
    },
    queryRight(row) {
      this.rightloading = true;
      this.$tool
        .request({
          url: "LIS/LIS9/LIS973",
          method: "post",
          data: {
            action: "queryRight",
            reportid: row.reportid,
            rpt_itemcode: row.rpt_itemcode,
          },
        })
        .then((response) => {
          if (response.errcode == "1") {
            this.rightTableData = response.MedData;
          } else {
            this.$alert(response.errmsg, "提示");
          }
          this.rightloading = false;
        })
        .catch((e) => {
          this.$alert(e, "出错");
          this.rightloading = false;
        });
    },
    BtnClear() {
      this.searchobj = {
        strdate: this.$pub.InitDate(),
        enddate: this.$pub.InitDate(),
        onlyposresult: 2,
        deletedup: 1,
        containHospcodeIsEmpty: "0",
        rejectGermComb: "0",
        reqdept: "",
        txtwardno: "",
        germgramflag: "0",
      };
      this.ExportConditionClear();
      this.leftTableData = [];
      this.rightTableData = [];
    },

    async BtnExport() {
      let data = this.$refs.leftxTable.getSelectRecords();
      if (data.length > 0) {
        let rloading = this.$loading({
          // 声明一个loading对象
          lock: true, // 是否锁屏
          text: "开始导出数据，请稍等！", // 加载动画的文字
          spinner: "el-icon-loading", // 引入的loading图标
          background: "rgba(0, 0, 0, 0.3)", // 背景颜色
          target: ".sub-main", // 需要遮罩的区域
          body: true,
          customClass: "mask", // 遮罩层新增类名
        });
        try {
          let reportidVsrpt_itemcode = "";
          data.forEach((item) => {
            let tempstr = item.reportid + "," + item.rpt_itemcode;
            reportidVsrpt_itemcode += tempstr + "|";
          });
          let filename = "WhonetData_" + this.searchobj.strdate + "_" + this.searchobj.enddate;
          let p = { prgno: "LIS971", filename: filename, reportidVsrpt_itemcode: reportidVsrpt_itemcode, deptmode: this.searchobj.deptmode, ...this.exportobj };
          await this.$pub.commexport(this, p, filename + ".txt", "text/html;charset=gb2312");
          rloading.close();
        } catch (e) {
          rloading.close();
        }
      } else {
        this.$alert("请选择需要导出的数据！", "提示");
      }
    },
    SelArr() {
      this.sumcnt = 0;
      let data = this.$refs.leftxTable.getSelectRecords();
      this.sumcnt = this.$refs.leftxTable.getSelectRecords().length;
      this.rptArr = "";
      this.codeArr = "";
      data.forEach((element) => {
        this.rptArr += ",'" + element.reportid + "'";
        this.codeArr += ",'" + element.rpt_itemcode + "'";
      });
      this.rptArr = this.rptArr.substring(1, this.rptArr.length);
      this.codeArr = this.codeArr.substring(1, this.codeArr.length);
    },
    BtnDbf() {
      //先去服务器查询是否存在模板DBF文件,
      //若存在 返回1,提示是否要上传覆盖,
      //若不存在 返回2,直接进入上传界面.
      let data = this.$refs.leftxTable.getSelectRecords();
      if (data.length > 0) {
        this.BtnQueryEx();
      } else {
        this.$alert("请选择需要导出的数据！", "提示");
        return false;
      }
    },
    BtnQueryEx() {
      this.$tool
        .request({
          url: "LIS/LIS9/LIS973",
          method: "post",
          data: {
            action: "haveex",
          },
        })
        .then((res) => {
          if ((res = "1")) {
            this.bMsgExportVisible = true;
          } else {
            this.bDbfExportVisible = true;
          }
        })
        .catch((e) => {
          console.log("error", e);
        });
    },
    BtnDBFExport() {
      this.logList = [];
      this.logListstr = "";
      this.exportdata = [];
      this.exportdata = this.$refs.leftxTable.getSelectRecords();
      if (this.exportdata.length > 0) {
        this.bDbfExportVisible = false;
        this.bMsgExportVisible = false;
        this.execexport = true;
        this.stopexec = false;
        this.logListstr += "开始后台生成DBF文件！<br/>";
        this.execDbfExport("", 0);
      } else {
        this.$alert("请选择需要导出的数据！", "提示");
      }
    },
    execDbfExport(dbfname, index) {
      // if(this.bShowlogVisible==false) return ;//关闭了导出消息框则终止调用
      if (this.stopexec) return; //人为中止
      if (index < this.exportdata.length) {
        let item = this.exportdata[index];
        this.$tool
          .request({
            url: "LIS/LIS9/LIS973",
            method: "post",
            data: {
              action: "dbfexportnew",
              ...this.exportobj,
              dbfname: dbfname,
              reportid: item.reportid,
              rpt_itemcode: item.rpt_itemcode,
              deptmode: localStorage.getItem("lis973deptmode"),
              laboratory: localStorage.getItem("lis973laboratory"),
            },
          })
          .then((res) => {
            if (res.errcode == "0") {
              this.logListstr += "文件生成过程中发生错误：" + res.errmsg + "<br/>";
            } else {
              this.execDbfExport(res.dbfname, index + 1);
              if (res.showmsg && res.showmsg.length > 0) {
                let sstr = "";
                res.showmsg.forEach((txt) => {
                  if (sstr == "") sstr = txt;
                  else sstr = sstr + "<br/>" + txt;
                });
                // this.logList.push(sstr);
                this.logListstr += sstr;
              }
              this.logListstr += "导出第  " + (index + 1) + " 条数据完成<br/>";
            }
          })
          .catch((e) => {
            this.logListstr += "文件生成过程中发生异常：" + e.message + "<br/>";
          });
      } else {
        //全部导完了
        this.logListstr += "后台数据生成结束！<br/>开始下载后台文件<br/>";
        console.log("dbfname", dbfname);
        let filename = this.searchobj.strdate.substring(0, 7).replace("-", "") + "." + (this.whonetextensionname ? this.whonetextensionname : "LIS");
        let p = { prgno: "LIS971_DBF", dbfname: dbfname, filename: filename };
        this.$pub
          .commexport(this, p, filename)
          .then(() => {
            this.logListstr += "文件下载结束！<br/>";
            setTimeout(() => {
              this.DelExport(dbfname);
            }, 100);
          })
          .catch(() => {
            this.logListstr += "文件下载出错！<br/>";
          });
      }
    },
    stopexport() {
      this.stopexec = true;
    },
    DelExport(dbfname) {
      this.$tool
        .request({
          url: "LIS/LIS9/LIS973",
          method: "post",
          data: {
            action: "delexport",
            dbfname: dbfname,
          },
        })
        .then((res) => {
          if (res.delflag == "1") {
            this.logListstr += "清除服务器临时文件完成<br/>本次导出结束！<br/>";
          } else {
            this.logListstr += "清除服务器临时文件出错" + res.delmsg + "<br/>本次导出结束！<br/>";
          }
        })
        .catch((e) => { });
    },
    btn_showselother() {
      this.is_showselother = !this.is_showselother;
    },
    handleCommand(name) {
      this.datename = name;
      if (name == "标本日期") {
        this.datetype = "1";
      } else {
        this.datetype = "2";
      }
    },
    ExportConditionSure() {
      this.exportConditionVisible = false;
    },
    ExportConditionClear() {
      this.exportobj = {
        PatnoShowPatid: "0",
        delCopySample: "0",
        micIsEmptyNouseResultFlag: "0",
        OnlyMicNotEmpty: "0",
        radIsEmptyNouseResultFlag: "0",
        OnlyRadNotEmpty: "0",
        chkdayu: "0",
        chkxiaoyu: "0",
        chkdayudengyu: "0",
        chkxiaoyudengyu: "0",
        chksynr: "1",
        chksyns: "1",
      };
    },
    formatFun({ cellValue, column, row }) {
      if (["hospcode", "hospitalcode"].includes(column.property)) {
        try {
          if (cellValue.toLowerCase() == "all") {
            return "全部医院";
          } else {
            let hospname = this.hospOption.find((m) => m.data == cellValue);
            if (hospname != undefined && hospname != null) {
              return hospname.display;
            } else {
              return cellValue;
            }
          }
        } catch { }
      } else if (["req_deptno"].includes(column.property)) {
        try {
          let deptname = this.deptOption.find((m) => m.data == cellValue);
          if (deptname != undefined && deptname != null) {
            return deptname.display;
          } else {
            return cellValue;
          }
        } catch { }
      } else if (["req_wardno"].includes(column.property)) {
        try {
          let wardname = this.wardOption.find((m) => m.data == cellValue);
          if (wardname != undefined && wardname != null) {
            return wardname.display;
          } else {
            return cellValue;
          }
        } catch { }
      } else if (column.property == "pat_typecode") {
        try {
          let pattypename = this.pattypeOption.find((m) => m.data == cellValue);
          if (pattypename != undefined && pattypename != null) {
            return pattypename.display;
          } else {
            return cellValue;
          }
        } catch { }
      } else if (["req_docno"].includes(column.property)) {
        //申请医生
        try {
          let doctorname = this.doctorOption.find((m) => m.data == cellValue);
          if (doctorname != undefined && doctorname != null) {
            return doctorname.display;
          } else {
            return cellValue;
          }
        } catch { }
      } else if (["rechk_user", "rechk2_user", "report_user"].includes(column.property)) {
        //检验医生，审核医生
        try {
          let username = this.userOption.find((m) => m.data == cellValue);
          if (username != undefined && username != null) {
            return username.display;
          } else {
            return cellValue;
          }
        } catch { }
      } else if (column.property == "rptunitid") {
        try {
          let rptunitname = this.rptunitOption.find((m) => m.data == cellValue);
          if (rptunitname != undefined && rptunitname != null) {
            return rptunitname.display + "[" + cellValue + "]";
          } else {
            return cellValue;
          }
        } catch { }
      } else if (column.property == "specimen_code") {
        try {
          let specimenname = this.specimenOption.find((m) => m.data == cellValue);
          if (specimenname != undefined && specimenname != null) {
            return specimenname.display;
          } else {
            return cellValue;
          }
        } catch {
          return cellValue;
        }
      } else if (column.property == "charge_flag") {
        try {
          let rptunitname = this.chargeflagOption.find((m) => m.value == cellValue);
          if (rptunitname != undefined && rptunitname != null) {
            return rptunitname.label;
          } else {
            return cellValue;
          }
        } catch { }
      } else if (column.property == "instrid") {
        try {
          let instr = this.instrOption.find((m) => m.data == cellValue);
          if (instr != undefined && instr != null) {
            console.log(instr.display);
            return instr.display;
          } else {
            return cellValue;
          }
        } catch {
          return cellValue;
        }
      } else {
        return cellValue;
      }
    },
    CellActive({ row, column }) {
      return false;
    },

    handleExceed(files, fileList) {
      this.$message.warning(`当前限制选择 1 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`);
    },
    // 上传文件之前的钩子, 参数为上传的文件,若返回 false 或者返回 Promise 且被 reject，则停止上传
    beforeUploadFile(file) {
      console.log(file);
      let extension = file.name.substring(file.name.lastIndexOf(".") + 1);
      console.log("extension", extension);
      let size = file.size / 1024 / 1024;
      if (extension != "DBF") {
        this.$notify.warning({
          title: "警告",
          message: `只能上传DBF(*DBF)文件`,
        });
        return false;
      }
    },
    uploadOpt(param) {
      var URL = this.$tool.baseUrl.replace("api", "z") + "fileupload";
      let formData = new FormData();
      formData.append("action", "LIS973");
      formData.append("file", param.file);
      axios
        .post(URL, formData, { "Content-Type": "multipart/form-data" })
        .then((res) => {
          this.$message({
            message: "上传模板成功。",
            type: "success",
          });

          this.bDbfExportVisible = false;
          this.bMsgExportVisible = true;
        })
        .catch((e) => {
          this.$alert(e, "出错");
        });
    },
    BtnExportDrugNet() {
      console.info("11111111111111111");
      let datalist = this.$refs.leftxTable.getSelectRecords();
      var reportidstr = "";
      if (datalist.length == 0) {
        this.$alert("请勾选要导出的数据");
        return false;
      } else {
        datalist.forEach((re) => {
          reportidstr += re.reportid + ":" + re.rpt_itemcode + ",";
        });
      }

      this.$tool
        .request({
          url: "LIS/LIS9/LIS973",
          method: "post",
          data: {
            action: "savedrugnet",
            reportidstr: reportidstr,
          },
        })
        .then((res) => {
          if (res.errcode == "1") {
            this.$alert("导出数据成功");
            return;
          } else {
            this.$alert(res.msg);
            return false;
          }
        })
        .catch((e) => { });
    },
  },
};
</script>

<style scoped>
.pagetop {
  width: 100%;
  height: 68px;
  display: -webkit-box;
  -webkit-box-pack: left;
  -webkit-box-align: center;
  border: 1px solid #ccc;
  position: absolute;
  z-index: 99;
}

.diapagetop {
  width: 100%;
  height: 35px;
  margin-bottom: 5px;
  display: -webkit-box;
  -webkit-box-pack: left;
  -webkit-box-align: center;
  border: 1px solid #ccc;
  z-index: 99;
}

.pagetopother {
  width: 100%;
  height: 158px;
  display: -webkit-box;
  -webkit-box-pack: left;
  -webkit-box-align: center;
  border: 1px solid #ccc;
  position: absolute;
  z-index: 99;
}

.pagecenter {
  position: absolute;
  top: 73px;
  width: 100%;
  left: 0;
  bottom: 0px;
  overflow: auto;
}

.pagecenterother {
  position: absolute;
  top: 163px;
  width: 100%;
  left: 0;
  bottom: 0px;
  overflow: auto;
}

.operation-list {
  float: right;
  margin-right: 5px;
  margin-bottom: 5px;
}

table {
  font-size: 12px;
  border-collapse: separate;
  border-spacing: 5px;
}

.el-input--suffix .el-input__inner {
  padding-right: 0px;
}

.search-param {
  display: inline-block;
}

.table1style tr td {
  /* padding: 0px 2px 0px 5px; */
}

::-webkit-scrollbar {
  width: 0px;
  height: 5px;
  border: 4px solid white;
}

::-webkit-scrollbar-thumb {
  background-color: #c1c1c1;
}

::-webkit-scrollbar-track {
  background-color: #f1f1f1;
}

/* Buttons */
::-webkit-scrollbar-button:single-button {
  background-color: #bbbbbb;
  display: block;
  border-style: solid;
  height: 5px;
  width: 5px;
}

/* Left */
::-webkit-scrollbar-button:horizontal:decrement {
  margin-right: 2px;
  border-width: 4px 4px 4px 0;
  border-color: #f1f1f1 transparent #f1f1f1 #f1f1f1;
  background-color: #000000;
}

::-webkit-scrollbar-button:horizontal:decrement:hover {
  border-color: #d2d2d2 transparent #d2d2d2 #d2d2d2;
}

/* Right */
::-webkit-scrollbar-button:horizontal:increment {
  margin-left: 2px;
  border-width: 4px 0 4px 4px;
  border-color: #f1f1f1 #f1f1f1 #f1f1f1 transparent;
  background-color: #000000;
}

::-webkit-scrollbar-button:horizontal:increment:hover {
  border-color: #d2d2d2 #d2d2d2 #d2d2d2 transparent;
}</style>
